<template>
	<view>
		<u-search placeholder="找一下你感兴趣的~" v-model="keyword" shape="square" input-align="center" bg-color="#fff"
			:show-action="false" @search="search">
		</u-search>
		<view class="search-main">
			<view class="search-main-title">
				<u-icon class="u-margin-right-6" name="pushpin" color="#2979ff" size="32"></u-icon><text
					style="color:#2979ff;">标签云</text>
			</view>
			<view class="search-main-content">
				<u-empty v-if="tagsList.length == 0" mode="data" text="正在加载..."></u-empty>
				<view v-else class="u-margin-6 dis-in-block" v-for="(tag,tIndex) in tagsList" :key="tIndex">
					<u-tag :text="tag.name" shape="circle" color="#7d9bce" border-color="#afc6ec" mode="plain"
						@click="tagDetail(tag.name)" />
				</view>
			</view>
			<u-line />
			<view class="search-main-list">
				<u-empty v-if="searchList.length == 0" mode="search"></u-empty>
				<view v-else class="list-item u-margin-bottom-30 u-padding-bottom-30" v-for="(item,index) in searchList" :key="index" @click="toDetail(item.id)">
					<text>{{item.title}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSearch
	} from '@/api/api.js'
	import {
		toDetail
	} from '@/comm/comm.js'

	export default {
		data() {
			return {
				keyword: '',
				tagsList: [],
				searchList: [],
				isLoading: true
			};
		},
		mounted() {
			this.getTges()
		},
		methods: {
			toDetail,
			getTges() {
				let list = this.$store.getters.tagList
				if (list.length <= 0) {
					setTimeout(_ => {
						this.tagsList = this.$store.getters.tagList
						this.isLoading = false
					}, 1500)
				} else {
					this.tagsList = list
				}
			},
			search() {
				getSearch(this.keyword).then(res => {
					this.searchList = res.data
				})
			},
			tagDetail(name) {
				this.keyword = name
				this.search()
			},
		}
	}
</script>


<style>
	page {
		background-color: #FFFFFF !important;
	}
</style>
<style lang="scss" scoped>
	.search-main {
		padding: 16rpx 30rpx;

		&-title {
			font-size: 16px;
		}

		&-content {
			padding: 10rpx;
		}

		&-list {
			padding: 30rpx 10rpx;
		}
	}

	.list-item {
		font-size: 16px;
		border-bottom: 1px solid #e4e7ed;
		    // padding-bottom: 15px;
	}
</style>
